﻿package com.video {
	
	/**
	 * ...
	 * @author wattonn
	 */
	
	import com.video.WebcamData;
	import flash.display.Sprite;
	import flash.media.Camera;
	import flash.media.Video;
	
	public class Webcam extends Sprite {
		
		private var vid:			Video;
		private var cam:			Camera;
		
		private var cameraW;
		private var cameraH;
		
		public function Webcam(data:WebcamData) {
			cameraW = data.width;
			cameraH = data.height;
		}
		
		private function setupCamera():Boolean {
			var ret:Boolean;
			vid = new Video(cameraW, cameraH);
			try{
				cam = Camera.getCamera();
				cam.setMode(cameraW, cameraH, Math.round(cam.fps * .75));
				vid.attachCamera(cam);
				addChild(vid);
				ret = true;
			}catch (Error) {
				ret = false;
			}
			return ret;
		}
		
		public function get webcam():Boolean {
			return setupCamera();
		}
		
	}

}